from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from pages.base_page import BasePage
from selenium.webdriver.common.alert import Alert

class CluePage(BasePage):
    """线索页面做的操作"""
    url='http://192.168.0.161/crm/index.php?m=leads'
    new_clue_btn_locator=(By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div > a')
    new_clue_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    select_checkbox_locator=(By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    batch_operate_locator=(By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > ul > li:nth-child(1) > div > a')
    batch_del_locator=(By.CSS_SELECTOR,'#delete')
    click_look_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(12) > a:nth-child(1)')
    click_search_pool_locator = (By.CSS_SELECTOR,'body > div.container > div.page-header > ul > li:nth-child(2) > a')
    click_client_locator = (By.CSS_SELECTOR,'body > div.navbar.navbar-inverse.navbar-fixed-top > div > div > div.nav-collapse.collapse > ul:nth-child(1) > li:nth-child(2) > a')
    select_first_locator = (By.CSS_SELECTOR, '#field')
    input_search_locator = (By.CSS_SELECTOR, '#search')
    click_search_locator = (By.CSS_SELECTOR, '#dosearch')
    clue_del_tips_locator= (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-error')
    click_transform_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(12) > a:nth-child(2)')
    select_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    clue_del_successful_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')

    def click_new_clue_btn(self):
        # 点击新建线索
        self.driver.find_element(*self.new_clue_btn_locator).click()

    def new_clue_tips(self):
        # 获取添加成功字样
        tips=self.driver.find_element(*self.new_clue_tips_locator).text
        return tips


    def select_checkbox(self):
        """勾选复选框  就是需要进行删除的第一步"""
        self.driver.find_element(*self.select_checkbox_locator).click()

    def click_batch_operate(self):
        """第二步 点击批量操作"""
        self.driver.find_element(*self.batch_operate_locator).click()

    def click_batch_del(self):
        """第三步 点击批量删除"""
        self.driver.find_element(*self.batch_del_locator).click()

    def alert(self):
        """第四步 会出现一个弹窗，那么直接返回一个弹窗后续可直接点击弹窗里面的东西"""
        return Alert(self.driver)

    def clue_del_tips(self):
        """第五步，断言，没有选择任何内容"""
        clue_del_tips=self.driver.find_element(*self.clue_del_tips_locator).text
        return clue_del_tips

    def clue_del_successful_tips(self):
        """断言，成功删除的"""
        del_successful_tips=self.driver.find_element(*self.clue_del_successful_tips_locator).text
        return del_successful_tips


    def click_look(self):
        """点击查看"""
        self.driver.find_element(*self.click_look_locator).click()

    def click_clue_pool(self):
        """#点击线索池"""
        self.driver.find_element(*self.click_search_pool_locator).click()

    def click_client(self):
        """#点击客户"""
        self.driver.find_element(*self.click_client_locator).click()

    def select_frist_search(self):
        """# 选择第一个筛选条件"""
        self.select_first_element=self.driver.find_element(*self.select_first_locator)

    def alert_search(self):
        """#弹出弹窗"""
        select = Select(self.select_first_element)
        select.select_by_index(1)

    def input_search_content(self,content):
        """# 填写搜索框内容"""
        self.driver.find_element(*self.input_search_locator).send_keys(content)

    def click_search_btn(self):
        """# 点击搜索"""
        self.driver.find_element(*self.click_search_locator).click()

    def click_transform(self):
        """#点击转换"""
        self.driver.find_element(*self.click_transform_locator).click()

    def select_clue_click_del(self):
        """# 勾选一个线索"""
        self.driver.find_element(*self.select_locator).click()



